package com.woniu.controller;

import com.woniu.common.CommonResult;
import com.woniu.entity.CommunityActivityUser;
import com.woniu.entity.PersonUser;
import com.woniu.service.CommunityActivityUserService;
import com.woniu.service.PersonUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CommunityActivityUser)表控制层
 *
 * @author makejava
 * @since 2020-03-30 02:11:07
 */
@RestController
@RequestMapping("/communityActivityUser")
public class CommunityActivityUserController {
    /**
     * 服务对象
     */
    @Resource
    private CommunityActivityUserService communityActivityUserService;

    @Resource
    PersonUserService personUserService;

    /**
     * 功能描述: 根据活动Id查询发起用户昵称
     * @Param: [id] 活动Id
     * @Return: com.woniu.common.CommonResult
     * @Author: yanghan
     * @Date: 2020/3/30 2:13
     */
    @GetMapping("/findUserNameByActivity/{id}")
    public CommonResult findUserNameByActivity(@PathVariable("id") Integer id){
        try {
            //用户Id
            Integer userId = communityActivityUserService.findUserNameByActivity(id);
            //根据用户Id查询昵称
            PersonUser personUser = personUserService.queryById(userId);
            return CommonResult.success(personUser.getNickname());
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("查询失败");
        }

    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public CommunityActivityUser selectOne(Integer id) {
        return this.communityActivityUserService.queryById(id);
    }

}